package org.example.review.feign;

import feign.Feign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * Feign客户端工厂类
 * 用于创建和管理Feign客户端实例
 */
@Component
public class FeignClientFactory {

    @Autowired
    private Feign.Builder feignBuilder;

    @Value("${feign.apply-service.url:http://localhost:8081}")
    private String applyServiceUrl;

    /**
     * 创建ApplyServiceClient实例
     * @return ApplyServiceClient
     */
    @Bean
    public ApplyServiceClient applyServiceClient() {
        return feignBuilder.target(ApplyServiceClient.class, applyServiceUrl);
    }

    /**
     * 通用方法：创建任意Feign客户端
     * @param clientClass 客户端接口类
     * @param url 目标服务URL
     * @param <T> 客户端类型
     * @return 客户端实例
     */
    public <T> T createClient(Class<T> clientClass, String url) {
        return feignBuilder.target(clientClass, url);
    }
}
